home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / program / oxcc1434.zip / SRC / BINIMG.H next >
C/C++ Source or Header  |  1995-11-01  |  61KB  |  1,557 lines

  1. /* binimg.h -- defs for a.out+coff+elf+pe+exe+ne+le+omf formats */
  2.  
  3. #ifndef __GNUC__
  4. #pragma pack(1)
  5. #define __attribute__()
  6. #endif
  7.  
  8. /* ****************** MAGIC NUMBERS ************************ */
  9. #define OBJMAGIC 0x80   /* omf THEADR record type, first byte */
  10. #define LIBMAGIC 0xF0   /* omf LIBR first byte */
  11. #define ARMAGIC  0x3c21 /* !< beginning of unix style archive */
  12. #define OMAGIC   0x0107    /* a.out object file 0407 */
  13. #define NMAGIC   0x0108    /* a.out pure executable 0410 */
  14. #define ZMAGIC   0x010b    /* a.out demand paged executable 0413 */
  15. #define IMAGIC   0x014c    /* coff header f_magic for i386 */
  16. #define AIXMAGIC 0x0175    /* coff header f_magic for aix i386 */
  17. #define MIBMAGIC 0x0162 /* coff header f_magic for mips big endian R3000 */
  18. #define MI3MAGIC 0x0162 /* coff header f_magic for mips little endian R3000 */
  19. #define MI4MAGIC 0x0166 /* coff header f_magic for mips little endian R4000 */
  20. #define MI1MAGIC 0x0166 /* coff header f_magic for mips little endian R10000 */
  21. #define AL1MAGIC 0x0184 /* coff header f_magic for Alpha AXP */
  22. #define AL2MAGIC 0x0186 /* coff header f_magic for Alpha APX */
  23. #define M68MAGIC 0x0268 /* coff header f_magic for M68000 series */
  24. #define PPCMAGIC 0x01f0 /* coff header f_magic for PowerPC little endian */
  25. #define PAMAGIC  0x0290 /* coff header f_magic for HP PA RISC */
  26. #define DOSMAGIC 0x5A4D    /* MZ start of .exe files */
  27. #define NEMAGIC  0x454E    /* NE os2,win31 16bit */
  28. #define LEMAGIC  0x454C /* LE os2,vxd 32 bit */
  29. #define PEMAGIC  0x4550 /* PE nt,win95,win32s */
  30. #define NTMAGIC  0x010b /* NT OPTIONAL HEADER */
  31. #define ROMMAGIC 0x0107 /* NT ROM OPTIONAL HEADER */
  32. #define OPOMAGIC 0x0104 /* coff optional header object file, as output */
  33. #define OPZMAGIC 0x010b /* coff optional header demand load format, ld output */
  34. #define OPTMAGIC 0x0101 /* coff optional header target shared library */
  35. #define OPHMAGIC 0x0123 /* coff optional header host shared library */
  36. #define ELFMAGIC 0x457f /* beginning of elf ident "\177ELF" */
  37.  
  38. /* ********************* FILE HEADERS *************************** */
  39.  
  40. #define NEW_EXECUTABLE(ptr) (ptr->e_lfarlc >= 0x0040)
  41.  
  42. typedef struct {      /* DOS .EXE header */
  43.     unsigned short   e_magic;       /* 00 Magic number */
  44.     unsigned short   e_cblp;        /* 02 Bytes on last page of file */
  45.     unsigned short   e_cp;          /* 04 Pages in file */
  46.     unsigned short   e_crlc;        /* 06 Relocations */
  47.     unsigned short   e_cparhdr;     /* 08 Size of header in paragraphs */
  48.     unsigned short   e_minalloc;    /* 0A Minimum extra paragraphs needed */
  49.     unsigned short   e_maxalloc;    /* 0C Maximum extra paragraphs needed */
  50.     unsigned short   e_ss;          /* 0E Initial (relative) SS value */
  51.     unsigned short   e_sp;          /* 10 Initial SP value */
  52.     unsigned short   e_csum;        /* 12 Checksum */
  53.     unsigned short   e_ip;          /* 14 Initial IP value */
  54.     unsigned short   e_cs;          /* 16 Initial (relative) CS value */
  55.     unsigned short   e_lfarlc;      /* 18 File address of relocation table */
  56.     unsigned short   e_ovno;        /* 1A Overlay number */
  57.     unsigned short   e_res[4];      /* 1C Reserved words */
  58.     unsigned short   e_oemid;       /* 24 OEM identifier (for e_oeminfo) */
  59.     unsigned short   e_oeminfo;     /* 26 OEM information; e_oemid specific */
  60.     unsigned short   e_res2[10];    /* 28 Reserved words */
  61.     long   e_lfanew __attribute__((packed));  /* 3C File address of new exe header */
  62.   } DOS_HDR, *PDOS_HDR;
  63.  
  64. typedef struct {      /* OS/2 .EXE header */
  65.     unsigned short   ne_magic;     /* Magic number */
  66.     char   ne_ver;                 /* Version number */
  67.     char   ne_rev;                 /* Revision number */
  68.     unsigned short   ne_enttab __attribute__((packed));/* Offset of Entry Table */
  69.     unsigned short   ne_cbenttab;  /* Number of bytes in Entry Table */
  70.     long   ne_crc __attribute__((packed)); /* Checksum of whole file */
  71.     unsigned short   ne_flags;     /* Flag word */
  72.     unsigned short   ne_autodata;  /* Automatic data segment number */
  73.     unsigned short   ne_heap;      /* Initial heap allocation */
  74.     unsigned short   ne_stack;     /* Initial stack allocation */
  75.     long   ne_csip __attribute__((packed)); /* Initial CS:IP setting */
  76.     long   ne_sssp;                /* Initial SS:SP setting */
  77.     unsigned short   ne_cseg;      /* Count of file segments */
  78.     unsigned short   ne_cmod;      /* Entries in Module Reference Table */
  79.     unsigned short   ne_cbnrestab; /* Size of non-resident name table */
  80.     unsigned short   ne_segtab;    /* Offset of Segment Table */
  81.     unsigned short   ne_rsrctab;   /* Offset of Resource Table */
  82.     unsigned short   ne_restab;    /* Offset of resident name table */
  83.     unsigned short   ne_modtab;    /* Offset of Module Reference Table */
  84.     unsigned short   ne_imptab;    /* Offset of Imported Names Table */
  85.     long   ne_nrestab __attribute__((packed)); /* Offset of Non-resident Names Table */
  86.     unsigned short   ne_cmovent;   /* Count of movable entries */
  87.     unsigned short   ne_align;     /* Segment alignment shift count */
  88.     unsigned short   ne_cres;      /* Count of resource segments */
  89.     unsigned char   ne_exetyp;     /* Target Operating system */
  90.     unsigned char   ne_flagsothers; /* Other .EXE flags */
  91.     unsigned short   ne_pretthunks __attribute__((packed)); /* offset to return thunks */
  92.     unsigned short   ne_psegrefbytes; /* offset to segment ref. bytes */
  93.     unsigned short   ne_swaparea;     /* Minimum code swap area size */
  94.     unsigned short   ne_expver;       /* Expected Windows version number */
  95.   } OS2_HDR, *POS2_HDR;
  96.  
  97. typedef struct {      /* WIN31 .EXE header */
  98.     unsigned short   ne_magic;     /* Magic number */
  99.     char   ne_ver;                 /* Version number */
  100.     char   ne_rev;                 /* Revision number */
  101.     unsigned short   ne_enttab __attribute__((packed));/* Offset of Entry Table */
  102.     unsigned short   ne_cbenttab;  /* Number of bytes in Entry Table */
  103.     long   ne_crc __attribute__((packed)); /* Checksum of whole file */
  104.     unsigned short   ne_flags;     /* Flag word */
  105.     unsigned short   ne_autodata;  /* Automatic data segment number */
  106.     unsigned short   ne_heap;      /* Initial heap allocation */
  107.     unsigned short   ne_stack;     /* Initial stack allocation */
  108.     long   ne_csip __attribute__((packed)); /* Initial CS:IP setting */
  109.     long   ne_sssp;                /* Initial SS:SP setting */
  110.     unsigned short   ne_cseg;      /* Count of file segments */
  111.     unsigned short   ne_cmod;      /* Entries in Module Reference Table */
  112.     unsigned short   ne_cbnrestab; /* Size of non-resident name table */
  113.     unsigned short   ne_segtab;    /* Offset of Segment Table */
  114.     unsigned short   ne_rsrctab;   /* Offset of Resource Table */
  115.     unsigned short   ne_restab;    /* Offset of resident name table */
  116.     unsigned short   ne_modtab;    /* Offset of Module Reference Table */
  117.     unsigned short   ne_imptab;    /* Offset of Imported Names Table */
  118.     long   ne_nrestab __attribute__((packed)); /* Offset of Non-resident Names Table */
  119.     unsigned short   ne_cmovent;   /* Count of movable entries */
  120.     unsigned short   ne_align;     /* Segment alignment shift count */
  121.     unsigned short   ne_cres;      /* Count of resource segments */
  122.     unsigned char   ne_exetyp;     /* Target Operating system */
  123.     unsigned char   ne_flagsothers; /* Other .EXE flags */
  124.     unsigned short   ne_fastload __attribute__((packed)); /* ofs in sectors to fast load area */
  125.     unsigned short   ne_fastsize; /* size in sectors of fast load area */
  126.     unsigned short   ne_swaparea;     /* reserved */
  127.     unsigned short   ne_expver;       /* Expected Windows version number */
  128.   } WIN31_HDR, *PWIN31_HDR;
  129.  
  130. typedef struct {      /* Windows VXD header */
  131.     unsigned short   e32_magic;       /* Magic number */
  132.     unsigned char   e32_border;       /* The byte ordering for the VXD */
  133.     unsigned char   e32_worder;       /* The word ordering for the VXD */
  134.     unsigned long  e32_level __attribute__((packed));